package com.lzh.others.basejava.Reflection;

import java.lang.reflect.InvocationTargetException;

/**
 * 为了更好的理解反射的实际应用场景
 * 简单模拟框架功能，创建一些通用方法，使得可以通过通用配置实现服务的依赖注入
 * <p>
 * 背景：假设我有一个Order对象
 */
public class Main_05 {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        //显示创建对象
//        Address address = new Address("未来", "100000");
//        Customer customer = new Customer("lzh", "807901483@qq.com");
//        Order order = new Order(address, customer);
//        order.getAddress().printStreet();
//        order.getCustomer().printName();

        Container container = new Container();
        container.init();
        Class<?> aClass = Class.forName("com.lzh.others.basejava.Reflection.Customer");
        Class<?> bClass = Class.forName("com.lzh.others.basejava.Reflection.Customer");
        Object aClass1 = container.getServiceInstanceByClass(aClass);
        Object byClass = container.getServiceInstanceByClass(bClass);
        System.out.println("aClass1 = " + aClass1);
        System.out.println("byClass = " + byClass);
        container.createInstance(bClass);

    }
}
